package com.example.fang.demodruid.concurrency;

public class MyObject {

    private int counter;

    //加1操作
    public synchronized void increase(){
        if(counter!=0){
           try {
               wait();//释放掉锁
           }catch (Exception e){
               e.printStackTrace();
           }
        }
        counter++;
        System.out.println(counter);
        notify();
    }

    //减1操作
    public synchronized void decrease(){
        if(counter==0){
          try {
              wait();//释放调锁
          }catch (Exception e){
              e.printStackTrace();
          }
        }
        counter--;
        System.out.println(counter);
        notify();
    }
}
